﻿
using System;

using System.Collections.Generic;
using System.Threading.Tasks;

//using Tea;
using System.Text.Json;
using RsCode;
//using static AlibabaCloud.SDK.Dysmsapi20170525.Models.QuerySmsTemplateListResponseBody;
//using AlibabaCloud.SDK.Dysmsapi20170525.Models;
//using static AlibabaCloud.SDK.Dysmsapi20170525.Models.QuerySmsSignListResponseBody;

namespace Rswl.Infrastructure
{
    /*阿里云短信SDK
     * AlibabaCloud.SDK.Dysmsapi20170525
     */
    public class SmsHelper
    {

        /**
         * 使用AK&SK初始化账号Client
         * @param accessKeyId
         * @param accessKeySecret
         * @return Client
         * @throws Exception
         */
        //public static AlibabaCloud.SDK.Dysmsapi20170525.Client CreateClient(string accessKeyId, string accessKeySecret)
        //{
        //    AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
        //    {
        //        // 必填，您的 AccessKey ID
        //        AccessKeyId = accessKeyId,
        //        // 必填，您的 AccessKey Secret
        //        AccessKeySecret = accessKeySecret,
        //    };
        //    // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
        //    config.Endpoint = "dysmsapi.aliyuncs.com";
        //    return new AlibabaCloud.SDK.Dysmsapi20170525.Client(config);
        //}

        //public static AlibabaCloud.SDK.Dysmsapi20170525.Client GetClient()
        //{
        //    var keyId = AppSettings.Get("aliyun:sms:accessKeyId");
        //    var keySecret = AppSettings.Get("aliyun:sms:accessKeySecret");
        //    AlibabaCloud.SDK.Dysmsapi20170525.Client client = CreateClient(keyId, keySecret);
        //    return client;
        //}

        public static void SendSms(string phones, string signName, string templateCode, string templateParam)
        {
            //AlibabaCloud.SDK.Dysmsapi20170525.Models.SendSmsRequest sendSmsRequest = new AlibabaCloud.SDK.Dysmsapi20170525.Models.SendSmsRequest
            //{
            //    PhoneNumbers = phones,
            //    SignName = signName,
            //    TemplateCode = templateCode,
            //    TemplateParam = templateParam
            //};
            //try
            //{
            //    AlibabaCloud.SDK.Dysmsapi20170525.Client client = GetClient();
            //    // 复制代码运行请自行打印 API 的返回值
            //    var ret = client.SendSmsWithOptions(sendSmsRequest, new AlibabaCloud.TeaUtil.Models.RuntimeOptions());
            //    if (ret.Body.Code != "OK")
            //        throw new Exception(ret.Body.Message);

            //}
            //catch (TeaException error)
            //{
            //    // 如有需要，请打印 error
            //    AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
            //}
            //catch (Exception _error)
            //{
            //    TeaException error = new TeaException(new Dictionary<string, object>
            //    {
            //        { "message", _error.Message }
            //    });
            //    // 如有需要，请打印 error
            //    AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
            //}
        }


        //public static async Task SendBatchSmsAsync(string[] phones, string[] signName, string templateCode, string templateParamJson)
        //{
        //    AlibabaCloud.SDK.Dysmsapi20170525.Models.SendBatchSmsRequest sendSmsRequest = new AlibabaCloud.SDK.Dysmsapi20170525.Models.SendBatchSmsRequest
        //    {
        //        PhoneNumberJson = JsonSerializer.Serialize(phones),
        //        SignNameJson = JsonSerializer.Serialize(signName),
        //        TemplateCode = templateCode,
        //        TemplateParamJson = templateParamJson
        //    };
        //    try
        //    {

        //        AlibabaCloud.SDK.Dysmsapi20170525.Client client = GetClient();
        //        // 复制代码运行请自行打印 API 的返回值
        //        var ret = await client.SendBatchSmsWithOptionsAsync(sendSmsRequest, new AlibabaCloud.TeaUtil.Models.RuntimeOptions());

        //        if (ret.Body.Code != "OK")
        //            throw new Exception(ret.Body.Message);
        //    }
        //    catch (TeaException error)
        //    {
        //        // 如有需要，请打印 error
        //        AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
        //    }
        //    catch (Exception _error)
        //    {
        //        TeaException error = new TeaException(new Dictionary<string, object>
        //        {
        //            { "message", _error.Message }
        //        });
        //        // 如有需要，请打印 error
        //        AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
        //    }
        //}


        //public static List<QuerySmsTemplateListResponseBodySmsTemplateList> GetSmsTemplate()
        //{

        //    AlibabaCloud.SDK.Dysmsapi20170525.Client client = GetClient();

        //    AlibabaCloud.SDK.Dysmsapi20170525.Models.QuerySmsTemplateListRequest querySmsTemplateListRequest = new AlibabaCloud.SDK.Dysmsapi20170525.Models.QuerySmsTemplateListRequest();
        //    AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
        //    try
        //    {
        //        // 复制代码运行请自行打印 API 的返回值
        //        var ret = client.QuerySmsTemplateListWithOptions(querySmsTemplateListRequest, runtime);
        //        return ret.Body.SmsTemplateList;
        //    }
        //    catch (TeaException error)
        //    {
        //        // 如有需要，请打印 error
        //        AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
        //        throw new Exception(error.Message);

        //    }
        //    catch (Exception _error)
        //    {
        //        TeaException error = new TeaException(new Dictionary<string, object>
        //        {
        //            { "message", _error.Message }
        //        });
        //        // 如有需要，请打印 error
        //        AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
        //        throw new Exception(error.Message);
        //    }
        //}



        //public static List<QuerySmsSignListResponseBodySmsSignList> GetSignList()
        //{
        //    AlibabaCloud.SDK.Dysmsapi20170525.Client client = GetClient();
        //    QuerySmsSignListRequest querySmsSignListRequest = new QuerySmsSignListRequest();
        //    AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
        //    try
        //    {
        //        // 复制代码运行请自行打印 API 的返回值
        //        var ret = client.QuerySmsSignListWithOptions(querySmsSignListRequest, runtime);
        //        return ret.Body.SmsSignList;
        //    }
        //    catch (TeaException error)
        //    {
        //        // 如有需要，请打印 error
        //        AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
        //        return null;
        //    }
        //    catch (Exception _error)
        //    {
        //        TeaException error = new TeaException(new Dictionary<string, object>
        //        {
        //            { "message", _error.Message }
        //        });
        //        // 如有需要，请打印 error
        //        AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
        //        return null;
        //    }
        //}



    }
}
